package moe.rename;

import java.util.regex.Pattern;

import moe.entity.Post;

public class RenameTagsToMD5 extends BaseRename {

	public RenameTagsToMD5() {
		super(Pattern.compile("^(?:moe|yande\\.re) \\d+ .+\\.[^.]+$", Pattern.CASE_INSENSITIVE));
	}

	@Override
	protected long getId(String fileName) {
		String id = fileName.split(" ")[1];
		return Long.valueOf(id);
	}

	@Override
	public String getNewFileName(String srcFileName, Post post) {
		String ext = srcFileName.substring(srcFileName.lastIndexOf('.'));
		StringBuilder fileName = new StringBuilder();
		fileName.append("moe ").append(post.id).append(".").append(post.md5).append(ext);
		return fileName.toString();
	}
}
